/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package br.com.estoque.AcessoBanco;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

/**
 *
 * @author note
 */
public class AcessoMysql {
    
    Connection con;
    
    public static void main(String[] args){
        new AcessoMysql();
    }
    
    public AcessoMysql(){
        conectar();
    }
    
   public Connection conectar(){
        try{
        Class.forName("com.mysql.jdbc.Driver");
        con = DriverManager.getConnection("jdbc:mysql://127.0.0.1/estoque","root","root");
        } catch(ClassNotFoundException ex){
            ex.printStackTrace();
            System.out.println("Não foi possível encontrar o Driver!");
        } catch(SQLException ex){
             ex.printStackTrace(); 
             System.out.println("Não foi possível conectar ao banco!");
        }  
        return con;
    }
   
    public void desconectar(){
        try {
            con.close();
        } catch (SQLException ex) {
            ex.printStackTrace();
        } 
    }
    
}
